package com.parking.bang.rpc.core.thread;

import java.util.concurrent.Executor;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * Thread Pool
 * 
 * @author ivan
 *
 */
public class RPCThreadPool {

	public static Executor getExecutor(int threads, int queues) {
		String name = "RPCThreadPool";
		ThreadPoolExecutor exe = new ThreadPoolExecutor(threads, threads, 0, TimeUnit.MILLISECONDS,
				queues == 0 ? new SynchronousQueue<Runnable>()
						: (queues < 0 ? new LinkedBlockingQueue<Runnable>()
								: new LinkedBlockingQueue<Runnable>(queues)),
				new RPCThreadFactory(name, true), new RPCThreadAbortPolicy(name));
		return exe;
	}
}
